//
//  GXDPPayViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/24.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "GXDPPayViewController.h"

#import "GXPayView.h"
#import "GXPayTwoView.h"
#import "GXPayCell.h"
#import "SelectPayCell.h"
@interface GXDPPayViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSArray *arrImgs;
    NSArray *arrTits;
}

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation GXDPPayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    [self showNav:@"订单"];
    arrImgs = @[@"微信2",@"支付宝-(1)",@"银联2",@"钱包-(1)"];
    arrTits = @[@"微信支付",@"支付宝支付",@"银联支付",@"余额支付"];
    [self loadUI];
    
    
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64-50) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-50, ScreenWidth, 50)];
    footView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footView];
    
    UIButton *btnPay = [UIButton buttonWithType:UIButtonTypeCustom];
    btnPay.frame = CGRectMake(ScreenWidth/3*2, 0, ScreenWidth/3, 50.0);
    btnPay.backgroundColor = [UIColor redColor];
    [btnPay setTitle:@"去支付" forState:UIControlStateNormal];
    [btnPay setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnPay addTarget:self action:@selector(clickPay) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:btnPay];
    
    UILabel *labPrice = [[UILabel alloc] init];
    labPrice.text = @"￥26.00";
    labPrice.textColor = [UIColor redColor];
    labPrice.font = [UIFont boldSystemFontOfSize:18.0];
    [footView addSubview:labPrice];
    [labPrice makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(footView.left).offset(16);
        make.top.equalTo(footView.top).offset(8);
    }];
    
    UILabel *labMethod = [[UILabel alloc] init];
    labMethod.text = @"微信支付";
    labMethod.textColor = [UIColor darkGrayColor];
    labMethod.font = [UIFont systemFontOfSize:12.0];
    [footView addSubview:labMethod];
    [labMethod makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(footView.left).offset(16);
        make.bottom.equalTo(footView.bottom).offset(-8);
    }];
    
    GXPayView *payView = [[[NSBundle mainBundle] loadNibNamed:@"GXPayView" owner:nil options:nil] lastObject];
    payView.frame = CGRectMake(0, 0, ScreenWidth, 100);
    _tableView.tableHeaderView = payView;
    
    GXPayTwoView *dpView = [[[NSBundle mainBundle] loadNibNamed:@"GXPayTwoView" owner:nil options:nil] lastObject];
    dpView.frame = CGRectMake(0, 0, ScreenWidth, 80);
    _tableView.tableFooterView = dpView;
    
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }
    return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString *cellId = @"Cell0";
        GXPayCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"GXPayCell" owner:nil options:nil] lastObject];
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row == 0) {
            cell.btnQues.hidden = YES;
            
        }else{
            cell.labNum.hidden = YES;
            cell.labName.text = @"配送费";
            [cell.btnQues addTarget:self action:@selector(showAlert) forControlEvents:UIControlEventTouchUpInside];
            
        }
        
        return cell;
    }else{
        static NSString *cellId = @"Cell1";
        SelectPayCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"SelectPayCell" owner:nil options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.images = arrImgs[indexPath.row];
        cell.labTit.textColor = arrTits[indexPath.row];
        
        return cell;
    }
    
}

- (void)showAlert{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"2公里范围为6元\n超出2公里每公里多收2元" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:action];
    
    [self presentViewController:alert animated:YES completion:nil];
}
//行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 44.0;
    }else{
        return 50.0;
    }
}

//头视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = [UIColor whiteColor];
        
        UILabel *lab = [[UILabel alloc] init];
        lab.text = @"洁净干洗店";
        lab.font = [UIFont systemFontOfSize:15.0];
        [view addSubview:lab];
        [lab makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view.centerX);
            make.centerY.equalTo(view.centerY);
        }];
        
        return view;
    }else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        
        UILabel *labLine = [[UILabel alloc] initWithFrame:CGRectMake(16, 10, 4, 20)];
        labLine.backgroundColor = [UIColor blueColor];
        [view addSubview:labLine];
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(28, 10, 150, 20)];
        lab.text = @"选择支付方式";
        lab.font = [UIFont systemFontOfSize:15.0];
        lab.font = [UIFont systemFontOfSize:15.0];
        [view addSubview:lab];
        
        return view;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0;
}
//尾视图
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = [UIColor whiteColor];
        
        UILabel *lab = [[UILabel alloc] init];
        lab.text = @"￥26.00元";
        lab.font = [UIFont boldSystemFontOfSize:18.0];
        [view addSubview:lab];
        [lab makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(view.right).offset(-16);
            make.bottom.equalTo(view.bottom).offset(-8);
        }];
        
        UILabel *lab2 = [[UILabel alloc] init];
        lab2.text = @"小计：";
        lab2.font = [UIFont systemFontOfSize:14.0];
        [view addSubview:lab2];
        [lab2 makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(lab.left).offset(0);
            make.bottom.equalTo(lab.bottom);
        }];
        
        return view;
    }else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        
        UILabel *labLine = [[UILabel alloc] initWithFrame:CGRectMake(16, 10, 4, 20)];
        labLine.backgroundColor = [UIColor blueColor];
        [view addSubview:labLine];
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(28, 10, 150, 20)];
        lab.text = @"备注";
        lab.font = [UIFont systemFontOfSize:15.0];
        lab.font = [UIFont systemFontOfSize:15.0];
        [view addSubview:lab];
        
        return view;
    }
    
}
//尾视图高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 40.0;
}

- (void)clickPay{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
